local aoqi__shenshi = fk.CreateSkill({
  name = "aoqi__shenshi",
  tags = { },
})

aoqi__shenshi:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local fixed_aoqi__shenshi = {
      "zhixvshenglong",    
      "huangjinshenglong",  
      "shikongshenglong",        
      "wujinshenglong",         
      "ciyuanshenglong",         
    }
    local aoqi__shenshi = {}
    for _, name in ipairs(fixed_aoqi__shenshi) do
      if Fk.generals[name] then
        table.insert(aoqi__shenshi, name)
      end
    end
    if #aoqi__shenshi == 0 then
      room:sendLog{
        type = "#NoWuGenerals",
        from = player.id,
      }
      return
    end
    table.shuffle(aoqi__shenshi)
    local options = {}
    local show_generals = {}
    for i = 1, #aoqi__shenshi do
      table.insert(show_generals, aoqi__shenshi[i])
      table.insert(options, Fk:translate(aoqi__shenshi[i]))
    end
    
    local params = {
      choices = options,
      skill_name = self.name,
      prompt = "#aoqi__shenshi-choose"
    }
    local choice = room:askToChoice(player, params)
    
    local selected_general = nil
    for i, option in ipairs(options) do
      if option == choice then
        selected_general = show_generals[i]
        break
      end
    end
    if not selected_general then return end
    
    local positions = {"mainhero", "deputyhero"}
    local position_choice = "deputyhero"  
    if player.deputyGeneral ~= "" and room.settings.enableDeputy then
      local params = {
        choices = positions,
        skill_name = self.name,
        prompt = "#aoqi__shenshi-position"
      }
      position_choice = room:askToChoice(player, params)
    end
    
    room:sendLog{
      type = "#shenshiChange",
      from = player.id,
      to = {player.id},
      arg = selected_general,
      arg2 = position_choice == "mainhero" and "主将" or "副将"
    }
    
    if position_choice == "mainhero" then
      room:changeHero(player, selected_general, false, false, true, true)
    else
      room:changeHero(player, selected_general, false, true, true, true)
    end
    
    room:setEmotion(player, "good")
  end,
})

Fk:loadTranslationTable{
  ["aoqi__shenshi"] = "神使",
  [":aoqi__shenshi"] = "每轮开始时，你可以从所有神使武将中选择一个作为副将<br><font color='blue'>神使名单</font>：正理，拉斐尔，神幻诺亚，神暗帝释天，魔无序，欲蝶。",
  ["#aoqi__shenshi-choose"] = "神使：请选择一个武将",
  ["#aoqi__shenshi-position"] = "神使：请选择更换主将还是副将",
  ["#shenshiChange"] = "%from 发动了【神使】，将 %to 的%arg2改为【%arg】",
  ["#NoWuGenerals"] = "%from 发动【神使】失败，没有找到包含\"神使\"字的武将",
  ["mainhero"] = "主将",
  ["deputyhero"] = "副将",
}

return aoqi__shenshi